package org.example.storage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.storage.mapper.StorageTblMapper;
import org.example.storage.model.StorageTbl;
import org.example.storage.service.StorageTblService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StorageTblServiceImpl extends ServiceImpl<StorageTblMapper, StorageTbl>
        implements StorageTblService {

    @Autowired
    private StorageTblMapper storageTblMapper;


    @Override
    @Transactional
    public void deduct(String commodityCode, Integer count) {
        StorageTbl storageTbl = storageTblMapper.findByCommodityCode(commodityCode);
        int currentCount = storageTbl.getCount() - count;
        storageTblMapper.updateCountByCommodityCode(commodityCode, currentCount);
        System.out.println("库存执行结束");
    }
}
